﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Caliburn.Micro;
using System.Windows.Forms;

namespace Presentation.ViewModels
{
    class GetFilePath: IResult
    {
        public enum FileDialogTypes { Open, Save};

        private FileDialogTypes _fileDialogType;

        public string Filter { get; set; }
        public string DefaultExt { get; set; }

        public string FilePath { get; private set; }

       public GetFilePath(FileDialogTypes type)
       {
           _fileDialogType = type;
       }

        public void Execute(ActionExecutionContext context)
        {
            FileDialog dlg;

            if (_fileDialogType == FileDialogTypes.Save)
            {
                dlg = new SaveFileDialog()
                {
                    Filter = Filter,
                    DefaultExt = DefaultExt,
                };
            }
            else
            {
                dlg = new OpenFileDialog()
                {
                    Filter = Filter,
                    DefaultExt = DefaultExt
                };
            }

            if (dlg.ShowDialog() ==  DialogResult.OK)
            {
                FilePath = dlg.FileName;
            }

            Completed(this, new ResultCompletionEventArgs());
        }

        public event EventHandler<ResultCompletionEventArgs> Completed = delegate { };
    }
}
